package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.model.DomainEpc;
import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.model.Epcunit;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.model.FunctionpointEpc;
import sjtu.ist.warehouse4ws.model.Role;
import sjtu.ist.warehouse4ws.model.RoleEpc;
import sjtu.ist.warehouse4ws.service.DomainEpcService;
import sjtu.ist.warehouse4ws.service.DomainModelService;
import sjtu.ist.warehouse4ws.service.EpcUnitService;
import sjtu.ist.warehouse4ws.service.EpcunitsService;
import sjtu.ist.warehouse4ws.service.FunctionpointEpcService;
import sjtu.ist.warehouse4ws.service.FunctionpointService;
import sjtu.ist.warehouse4ws.service.RoleEpcService;
import sjtu.ist.warehouse4ws.service.RoleService;

import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;



public class ShowEpcAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5605567980406358826L;
	private List<Epcunit> epcList = new ArrayList<Epcunit> ();
	private List<Role> roleList = new ArrayList<Role> ();
	private List<Functionpoint> functionpointList = new ArrayList<Functionpoint> ();
	private List<Domainmodel> domainmodelList = new ArrayList<Domainmodel> ();
	private EpcUnitService epcunitService;
	private RoleEpcService roleEpcService;
	private RoleService roleService;
	private FunctionpointEpcService functionpointEpcService;
	private FunctionpointService functionpointService;
	private DomainEpcService domainEpcService;
	private DomainModelService domainModelService;
	private String xmlName;
	private String uid;
	
	private boolean success = false;
	
	
	
	@JSON(name = "success")
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	@JSON(name ="Role")	
	public List<Role> getRoleList() {
		return roleList;
	}
	@JSON(name = "totalRole")	
	public int getTotalRole() {
		return this.roleList.size();
	}
	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public void setRoleEpcService(RoleEpcService roleEpcService) {
		this.roleEpcService = roleEpcService;
	}
	
	@JSON(name ="Function")	
	public List<Functionpoint> getFunctionpointList() {
		return functionpointList;
	}
	@JSON(name = "totalFunctionpoint")	
	public int getTotalFunctionpoint() {
		return this.functionpointList.size();
	}
	public void setFunctionpointList(List<Functionpoint> functionpointList) {
		this.functionpointList = functionpointList;
	}

	public void setFunctionpointService(FunctionpointService functionpointService) {
		this.functionpointService = functionpointService;
	}

	public void setFunctionpointEpcService(FunctionpointEpcService functionpointEpcService) {
		this.functionpointEpcService = functionpointEpcService;
	}
	
	@JSON(name ="DomainModel")	
	public List<Domainmodel> getDomainmodelList() {
		return domainmodelList;
	}
	@JSON(name = "totalDomainModel")	
	public int getTotalDomainmodel() {
		return this.domainmodelList.size();
	}
	public void setDomainmodelList(List<Domainmodel> domainmodelList) {
		this.domainmodelList = domainmodelList;
	}

	public void setDomainModelService(DomainModelService domainModelService) {
		this.domainModelService = domainModelService;
	}

	public void setDomainEpcService(DomainEpcService domainEpcService) {
		this.domainEpcService = domainEpcService;
	}


	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}



	public void setEpcUnitService(EpcUnitService epcunitService){
		this.epcunitService=epcunitService;
	}


	public String getXmlName() {
		return xmlName;
	}
	public void setXmlName(String xmlName) {
		this.xmlName = xmlName;
	}
	public void setEpcList(List<Epcunit> epcList) {
		this.epcList = epcList;
	}
	//EpcModel
	public String showEpc(){
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.xmlName=request.getParameter("text");
		
		this.epcList=epcunitService.getEpcunitListById(xmlName);
		
		this.success=true;
		return SUCCESS;
	}
	public String gotoRole(){
		
			List<RoleEpc> roleEpcList=roleEpcService.find(uid);
			String roleUid=roleEpcList.get(0).getRoleUid();
		    roleList=roleService.getRoleListByUid(roleUid);
			this.success=true;
		    return SUCCESS;
	}
	public String gotoFunctionpoint(){
		
		List<FunctionpointEpc> functionpointEpcList=functionpointEpcService.find(uid);
		String functionpointUid=functionpointEpcList.get(0).getFunctionUid();
	    functionpointList=functionpointService.getFunctionpointListByUid(functionpointUid);
		this.success=true;
	    return SUCCESS;
	}
	public String gotoDomainModel(){
		
		List<DomainEpc> domainEpcList=domainEpcService.find(uid);
		String domainUid=domainEpcList.get(0).getDomainUid();
	    domainmodelList=domainModelService.getDomainmodelListByUid(domainUid);
		this.success=true;
	    return SUCCESS;
	}
	
	@JSON(name = "totalEpc")	
	public int getTotalEpc() {
		return this.epcList.size();
	}
    
	@JSON(name ="Epc")	
	public List<Epcunit> getEpcList() {
		return this.epcList;
	}

}
